/*
 * AXP17x.h
 *
 *  Created on: 2016-6-23
 *      Author: NKJ
 */

#ifndef _BSP_AXP17X_H_
#define _BSP_AXP17X_H_

#include "stm32l4xx_hal.h"

//需要重定义的函数
void UsbInCallBack(void);
void UsbOutCallBack(void);
void BatteryInCallBack(void);
void BatteryOutCallBack(void);
void keyShortPressCallback(void);
void keyLongPressCallback(void);
void PoweringCallBack(void);
void PoweredCallBack(void);
void DCDC1LowCallBack(void);
void LowPowerCallBack(void);

#define SPORTS_UNIT_B

#if defined SPORTS_UNIT_UWB_NEMO

#include "soft_iic.h"
#include "misc_func.h"

#define axp17x_i2cinit()						   				//初始化IIC
#define axp17x_IRQinit()										//初始化IRQ
#define AXP17x_Read(readi2caddr,reg,data,len)		IIC_Read_Device(readi2caddr,reg,data,len)//IIC读取
#define AXP17x_Write(writei2caddr,reg,data,len)		IIC_Write_Device(writei2caddr,reg,data,len)//IIC写入

#define axp17x_delayms(t)							delay_ms(t)//ms延时
#define CloseAllDevice()							//关闭所有设备 及其电源输出 注意AXP  IIC 与主MCU 不能掉电,
#define OpenAllDevice()								//打开所有设备及其电源

#elif defined SPORTS_UNIT_A

#elif defined SPORTS_UNIT_B

#include "axp17x.h"

extern I2C_HandleTypeDef hi2c2;



static inline uint8_t IIC_Write_Axp17x(uint16_t addr, uint16_t reg,uint8_t* data,uint16_t len)
{
  for(int i = 0;i < len;i ++)
  {
	  HAL_I2C_Mem_Write(&hi2c2,addr,reg + i,1,&(data[i]),1,1);

  }
  return 0;
}


#define axp17x_i2cinit()						   				//初始化IIC
#define axp17x_IRQinit()										//初始化IRQ
#define AXP17x_Read(readi2caddr,reg,data,len)		HAL_I2C_Mem_Read(&hi2c2,readi2caddr,reg,1,data,len,len)//IIC读取
#define AXP17x_Write(writei2caddr,reg,data,len)		IIC_Write_Axp17x(writei2caddr,reg,data,len)//IIC写入

#define axp17x_delayms(t)							HAL_Delay(t)//ms延时
#define CloseAllDevice()							//关闭所有设备 及其电源输出 注意AXP  IIC 与主MCU 不能掉电,
#define OpenAllDevice()								//打开所有设备及其电源

#endif

#endif /* AXP17x_H_ */
